/* Copyright (c) 2021-2022 Qualcomm Technologies International, Ltd. */
/* %%version */

/*!
@file    gatt_cas_server.h
@brief   Header file for the GATT CAS (Common Audio Service) Server library.

        This file provides documentation for the GATT CAS server library
        API (library name: gatt_cas_server).
*/

#ifndef GATT_CAS_H_
#define GATT_CAS_H_

#include <service_handle.h>
#include "csr_bt_gatt_prim.h"
#include "csr_bt_tasks.h"

/* Maximum number of GATT connections */
#define GATT_CAS_MAX_CONNECTIONS (3)

/*! @brief Definition of data required for the initialisation
 *         of the CAS Server Library.
 */
typedef struct
{
    /* None */
    unsigned    unused:16;
} GattCasInitData;

/*! @brief Client Config data.

    This structure contains the client configuration of all the characteristics
    of CAS
 */
typedef struct
{
    /* No characteristics */
    unsigned    unused:16;
} GattCasServerConfig;


/*! @brief Enumeration of messages an application task can receive from the
    GATT CAS Server library
 */
typedef enum {
    GATT_CAS_SERVER_IND,
    GATT_CAS_SERVER_MESSAGE_TOP
} GattVcsMessageId;


/*! @brief Instantiate the GATT CAS Server Service Library.
 
    The GATT Service Init function is responsible for allocating its instance memory
    and returning a unique service handle for that instance. The Service handle is
    then used for the rest of the API.

    @param theAppTask The client task that will receive messages from this Service.
    @param startHandle The first handle in the ATT database for this Service instance.
    @param endHandle The last handle in the ATT database for this Service instance.
    @param initData The initialisation data to set

    @return ServiceHandle If the service handle returned is 0, this indicates a failure
                             during GATT Service initialisation.
*/
ServiceHandle GattCasServerInit(
                     AppTask theAppTask,
                     uint16  startHandle,
                     uint16  endHandle,
                     GattCasInitData initData);

/*!
    \brief Add configuration for a paired peer device, identified by its
    Connection ID (CID).

    \param srvcHndl Instance handle for the service.
    \param cid The Connection ID to the peer device.
    \param config Client characteristic configurations for this connection.
           If this is NULL, this indicates a default config should be used for the
           peer device identified by the CID.
    \return gatt_status_t status of the Add Configuration operation.
*/
status_t GattCasServerAddConfig(
                  ServiceHandle               srvcHndl,
                  connection_id_t                cid,
                  const GattCasServerConfig *config);

/*!
    \brief Remove the configuration for a peer device, identified by its
           Connection ID.

    This removes the configuration for that peer device from the
    service library, freeing the resources used for that config.
    This should only be done when the peer device is disconnecting.

    \param srvcHndl The GATT service instance handle.
    \param cid A Connection ID for the peer device.

    \return gatt_cas_server_config_t Pointer to the peer device configuration
            data. It is the applications responsibility to cache/store
            this between connections of paired peer devices, and for
            freeing the allocated memory.
            If the connection_id_t is not found, the function will return NULL.
*/
GattCasServerConfig * GattCasServerRemoveConfig(
                        ServiceHandle srvcHndl,
                        connection_id_t  cid);


#endif /* GATT_CAS_SERVER_H_ */
